package com.hongyuan.sellfitness.ui.home.activity;

import android.os.Bundle;
import androidx.lifecycle.ViewModelProviders;
import com.hongyuan.sellfitness.R;
import com.hongyuan.sellfitness.base.AppViewModelFactory;
import com.hongyuan.sellfitness.base.Constants;
import com.hongyuan.sellfitness.base.CustomActivity;
import com.hongyuan.sellfitness.databinding.ActivityCardDetailsBinding;
import com.hongyuan.sellfitness.ui.home.view_mode.CardDetailsViewModel;
import me.tatarka.bindingcollectionadapter2.BR;

public class CardDetailsActivity extends CustomActivity<ActivityCardDetailsBinding, CardDetailsViewModel> {

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_card_details;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public CardDetailsViewModel initViewModel() {
        //使用自定义的ViewModelFactory来创建ViewModel，如果不重写该方法，则默认会调用NetWorkViewModel(@NonNull Application application)构造方法
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this, factory).get(CardDetailsViewModel.class);
    }

    @Override
    public void initView() {
        super.initView();

        setOnRefresh(binding.refresh,REFRESH_0X4);

        binding.comBack.setOnClickListener(view -> finish());
    }

    @Override
    public void initData() {
        super.initData();

        viewModel.clearParams().setParams("card_id",getBundle().getString("card_id"));

        viewModel.requestData(Constants.GET_CARD_INFO);
    }
}
